/**
 * caicongyang.com Inc.
 * Copyright (c) 2004-2017 All Rights Reserved.
 */
package com.caicongyang.design.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @author caicongyang1
 * @version id: Composite, v 0.1 17/5/18 下午8:16 caicongyang1 Exp $$
 */
public class Composite extends Component {

    private List<Component> list = new ArrayList<>();

    public Composite(String name) {
        super(name);
    }

    @Override
    public void add(Component component) {
        list.add(component);
    }

    @Override
    public void remove(Component component) {
        list.add(component);
    }

    @Override
    public void dispay(int detph) {
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < detph; i++) {
            stringBuilder.append("-");
        }
        stringBuilder.append(super.getName());
        System.out.println(stringBuilder.toString());

        for (Component component : list) {
            component.dispay(detph + 2);
        }
    }
}
